﻿using System;
using System.Text.RegularExpressions;

namespace YEA.Monitor.NotificationManager
{
    public interface IContentAnalyzer
    {
        ContentFlag Analyze(string content);
    }
    public class ContentAnalyzer : IContentAnalyzer
    {
        private Regex BlockedWords;
        private Regex IUOWords;
        private Regex ApplicationData;

        public ContentAnalyzer()
        {
            RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Singleline;
            var blockedPattern = @"(credit\s+card|creditcard|\d{14})";
            var iuoPattern = @"(report|social\s+security\s+number|ss#|\d{3}\s+\d{2}\s+\d{3})";
            var appData = @"(stacktrace|exception)";
            BlockedWords = new Regex(blockedPattern, options);
            IUOWords = new Regex(iuoPattern, options);
            ApplicationData = new Regex(appData, options);
        }
        public ContentFlag Analyze(string content)
        {
            ContentFlag result = ContentFlag.Ok;
            if (BlockedWords.IsMatch(content))
                result |= ContentFlag.Blocked;
            if (IUOWords.IsMatch(content))
                result |= ContentFlag.InternalUseOnly;
            if (ApplicationData.IsMatch(content))
                result |= ContentFlag.InternalUseOnly;
            return result;
        }
    }
}
